﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Runtime.Serialization;
using Core.Domain;
using System.Linq.Expressions;

namespace Core.Queries
{
    [Serializable()]
    public class PersonQuery : Query<Person>
    {
        public string Name { get; set; }

        public override Expression<Func<Person, bool>> ToExpression()
        {   
            Expression<Func<Person, bool>> predicate = x => true;

            if (!string.IsNullOrWhiteSpace(Name))
                predicate = x => x.Name.StartsWith(Name);

            return predicate;
        }       
    }
}
